package com.maze.game.model.entity
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	
	public class Entity extends Sprite
	{
		protected var areaX:Number;
		protected var areaY:Number;
		protected var areaX2:Number;
		protected var areaY2:Number;
		public var obstacles:Sprite;

		public function Entity()
		{
			super();
		}

		public function setMoveArea(areaX:Number, areaY:Number, areaX2:Number, areaY2:Number, obstacles:Sprite):void
		{
			this.areaX = areaX;
			this.areaY = areaY;
			this.areaX2 = areaX2-width;
			this.areaY2 = areaY2-height;
			this.obstacles = obstacles;
		}

		public function checkAreaX(posx:Number):Boolean
		{
			return (posx>areaX&&posx<areaX2);
		}
		
		public function checkAreaY(posy:Number):Boolean
		{
			return (posy>areaY&&posy<areaY2);
		}

		public function checkObstacle():Boolean
		{
			var hit:Boolean = false;
			if(this.hitTestObject(this.obstacles))
			{
				hit = true;
			}
			return hit;
		}

		public function getObstacle():DisplayObject
		{
			var returnValue:DisplayObject = null;
			var countChild:int = obstacles.numChildren;
			var obstacle:DisplayObject;
			for(var i:int = 0; i<countChild; i++)
			{
				obstacle = obstacles.getChildAt(i);
				if(this.hitTestObject(obstacle))
				{
					returnValue = obstacle;
				}
			}
			return returnValue;
		}
	}
}